package org.idea.qiyu.framework.utils.queue;


import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author linhao
 * @Date created in 4:59 下午 2022/1/12
 */
public class DisplayThread {

    private ReentrantLock reentrantLock = new ReentrantLock();

    private Condition write = reentrantLock.newCondition();

    public Thread thread1 = new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                reentrantLock.lock();
                try {
                    write.await();
                    System.out.print(1);
                } catch (Exception e) {
                } finally {
                    reentrantLock.unlock();
                }
            }
        }
    });


    public Thread thread2 = new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                reentrantLock.lock();
                try {
                    write.signal();
                } catch (Exception e) {
                } finally {
                    reentrantLock.unlock();
                }
            }
        }
    });

    public static void main(String[] args) throws InterruptedException {
        DisplayThread displayThread = new DisplayThread();
        displayThread.thread1.start();
        displayThread.thread2.start();
        Thread.yield();
    }
}
